package com.juku2024.juku.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.juku2024.juku.R
import com.juku2024.juku.db.entity.HistoryEntity
import com.juku2024.juku.tools.ImageUtils
import com.juku2024.juku.tools.TimeUtils

class HistoryAdapter(historyVideoBeans: ArrayList<HistoryEntity>) :
        BaseQuickAdapter<HistoryEntity, BaseViewHolder>(R.layout.item_history, historyVideoBeans) {

    var isEditStatus = false


    override fun convert(holder: BaseViewHolder, item: HistoryEntity) {
        val imageView = holder.getView<ImageView>(R.id.ivHistory)
        ImageUtils.loadImageV(imageView, item.pic)

        holder.setText(R.id.tvNameHistory, item.name)
                .setText(R.id.tvPlayEpisodeHistory, String.format("播放到第%d集", item.episode + 1))
                .setText(R.id.tvPlayTime, String.format("已观看到：%s", TimeUtils.getHMSTime(item.progress)))
            .setGone(R.id.edit_button_fl_h, !isEditStatus)

        val resId = if (item.isSelect) {
            R.drawable.ic_checked
        } else {
            R.drawable.ic_check_normal
        }
        holder.setBackgroundResource(R.id.ivEditHistory, resId)


        // 当有更新的时候
        holder.setGone(R.id.tvUpdate, !item.isNewEpisode)
    }
}